#include <stdio.h>
#include "QHDX_main.h"

void UpdataStudentInfo()
{
	int UpNumber;
	struct StudentInfo FindStudent, UpStudent;
	printf("\n***欢迎使用修改模式***\n");
	while(1)
	{
		printf("\n请输入您想修改学生的学号:");
		scanf("%d", &UpNumber);

		if(1 != Is_Student_Exist(UpNumber))
		{
			printf("\n未找到该学生信息，请重新输入！\n");
			while(getchar() != '\n');
			continue;
		}
		else
		{
				
			FILE* fp = fopen("StudentData", "r+b");
			while(fread(&FindStudent, sizeof(FindStudent), 1, fp))
			{
				if(FindStudent.number == UpNumber)
				{
					UpStudent.number = UpNumber;	
				
					printf("请输入学生姓名:>");
					scanf("%s", UpStudent.name);
		
					printf("请输入学生性别(女生输入0,男生输入1):>");
					scanf("%hd", &UpStudent.sex);
			
					printf("请输入学生语文成绩:>");
					scanf("%d", &UpStudent.grade.Chinese);
			
					printf("请输入学生数学成绩:>");
					scanf("%d", &UpStudent.grade.Math);
			
					printf("请输入学生英语成绩:>");
					scanf("%d", &UpStudent.grade.English);

					fseek(fp, -sizeof(FindStudent), SEEK_CUR);
					fwrite(&UpStudent, sizeof(UpStudent), 1, fp);
					fclose(fp);
					break;
				}
			}
			printf("\n是否继续删除学生信息(y/n)\n");
			getchar();
			if(getchar() != 'y') break;
		}
	}
}
